package com.ai.dmc.utils.remotecall;

import java.util.List;

import javax.xml.namespace.QName;

import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.log4j.Logger;

import com.ai.dmc.utils.remotecall.bean.Interface;
import com.ai.dmc.utils.remotecall.bean.Result;


public class WebserviceUtil extends WsClient{
	Logger log = Logger.getLogger(WebserviceUtil.class);
	/**
	 * 
	 * @param wsdl
	 * @param targetNamespace
	 * @param methodName
	 * @param args
	 * @return
	 */
	public Object[] callWebServCXF(String wsdl, String targetNamespace, String methodName, Object args[]) {
        Object[] res = null;
        try {
            log.info("动态调用webservice开始，wsdl:"+wsdl+",methodName:"+methodName+",args:" + args);
            
            JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
            Client client = dcf.createClient(wsdl);
            
            if (targetNamespace == null) {
                res = client.invoke(methodName, args);
            } else {
                res = client.invoke(new QName(targetNamespace, methodName), args);
            }
           
        } catch (Exception e) {
            log.error("动态调用webservice 失败,wsdl:" + wsdl + ",targetNamespace:" + targetNamespace + ",methodName:"
                    + methodName + ",args:" + args, e);
        }
        return res;
    }
	@Override
	protected List<SOAPHeaderBlock> createSoapHeaderDatas(Interface ifc) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Result callWebServAXIS(Interface ifc, String... datas) throws Exception {
		return super.call(ifc, datas);
	}

}
